﻿@page
@using OpenCqrs.Sample.NoEventSourcing.Domain
@model ListModel
@{
    ViewData["Title"] = "List";
}

<h1>Products</h1>
<form method="post">
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">Name</th>
            <th scope="col">Description</th>
            <th scope="col">Price</th>
            <th scope="col">Published</th>
            <th scope="col"></th>
        </tr>
        </thead>
        <tbody>
        @foreach (var product in Model.Products)
        {
            <tr>
                <td>@product.Name</td>
                <td>@product.Description</td>
                <td>@product.Price</td>
                <td>
                    @if (product.Status == ProductStatus.Published)
                    {
                        <label>Yes</label>
                    }
                </td>
                <td>
                    <a asp-page="./Edit" asp-route-id="@product.Id" class="btn btn-secondary" role="button">Edit</a>
                    <button type="submit" asp-page-handler="Delete"
                            asp-route-id="@product.Id" class="btn btn-danger">
                        Delete
                    </button>
                    @if (product.Status == ProductStatus.Draft)
                    {
                        <button type="submit" asp-page-handler="Publish"
                                asp-route-id="@product.Id" class="btn btn-primary">
                            Publish
                        </button>
                    }
                    else if (product.Status == ProductStatus.Published)
                    {
                        <button type="submit" asp-page-handler="Withdraw"
                                asp-route-id="@product.Id" class="btn btn-primary">
                            Withdraw
                        </button>
                    }
                </td>
            </tr>
        }
        </tbody>
    </table>

    <a asp-page="./Create" class="btn btn-primary" role="button">Create</a>
</form>

